package org.example.basic.optional;


import org.example.basic.entity.UserEntity;

import java.time.LocalDate;
import java.util.Optional;

public class OptionalTest2 {
    public static void main(String[] args) {
        UserEntity userEntity = new UserEntity(4L, 21, "song", LocalDate.now().minusYears(4));
        Optional<UserEntity> u1 = Optional.empty();
        Optional<UserEntity> u2 = Optional.of(new UserEntity());
        Optional<UserEntity> u3 = Optional.ofNullable(userEntity);

//        System.out.println(u1.get()); //报错：NoSuchElementException
        System.out.println(u2.get().toString());
        System.out.println(u3.get().toString());

    }


}
